package pl.ydp.storage
{
	import flash.events.IEventDispatcher;
	import flash.net.FileFilter;
	import flash.utils.ByteArray;
	
		
	[Event(name="fileLoadCompleted", type="StorageEvent")]
	[Event(name="putFileStarted", type="StorageEvent")]
	[Event(name="putFileCompleted", type="StorageEvent")]
	[Event(name="removeFileCompleted", type="StorageEvent")]
	[Event(name="saveFileCompleted", type="StorageEvent")]
	[Event(name="putSelectCancel", type="StorageEvent")]
	[Event(name="listDirCompleted", type="ListFilesEvent")]
	
	[Event(name="fileLoadError", type="StorageErrorEvent")]
	[Event(name="putFileError", type="StorageErrorEvent")]
	[Event(name="saveFileError", type="StorageErrorEvent")]
	[Event(name="removeFileError", type="StorageErrorEvent")]
	[Event(name="listDirError", type="StorageErrorEvent")]
	[Event(name="listDirError", type="StorageErrorEvent")]
	
	[Event(name="copyFileCompleted", type="StorageErrorEvent")]
	[Event(name="copyFileError", type="StorageErrorEvent")]
	
	
	
	/**
	 * Interafce specifies operations that single resource should be able to perform.
	 * All file operations are made thru the implementations of IResource    
	 *  
	 * @see pl.ydp.storage.IStorage
	 * @see pl.ydp.storage.events.StorageEvent
	 * @see pl.ydp.storage.events.StorageListEvent
	 * @see pl.ydp.storage.events.StorageErrorEvent
	 */
	 
	
	public interface IResource extends IEventDispatcher
	{
		
		/**
		 * Loads data from resource specified by the 'path' parameter
		 * Content should be return via StorageEvent.LOAD_COMPLETED event
		 * @see  pl.ydp.storage.StorageEvent
		 */
		 
		function load(dataFormat:String = null):void;
		
		
		/**
		 * starts upload/copy of a resource.
		 * Data will we writen to the resource 'path'  
		 * @param fileFilter specifies allowed extensions
		 * @param newFileName allows to define name with which uploaded file will be created    
		 * @param forceOverwrite If false, upload fails if the target file already exists. If true, any existing file will be overwritten.
		 * Following events should be dispatched while perfoming "put": 
		 * StorageErrorEvent.PUT_ERROR, StorageEvent.PUT_COMPLETED, 
		 * StorageEvent.PUT_STARTED, ProgressEvent.PROGRESS
		 * StorageErrorEvent.PROPERTY_LIST_ERROR 
		 */
		function startPutDialog(fileFilter:FileFilter=null, newFileName:String=null, forceOverwrite:Boolean=false):void;
		
		
		/**
		 * starts upload/copy of a resource list.
		 * Data will we writen to the resource 'path'  
		 * @param fileFilter specifies allowed extensions
		 * Following events should be dispatched while perfoming "put": 
		 * StorageErrorEvent.PUT_ERROR, StorageEvent.PUT_COMPLETED, 
		 * StorageEvent.PUT_STARTED, ProgressEvent.PROGRESS
		 * StorageErrorEvent.PROPERTY_LIST_ERROR 
		 */
		function startPutListDialog( fileFilter:FileFilter=null ):void
		
		
		/**
		 * starts upload a zip file.
		 * Files will we extracted to the resource 'path'  
		 * @param fileFilter specifies allowed extensions
		 * @param newFileName allows to define name with which uploaded file will be created    
		 * Following events should be dispatched while perfoming "put": 
		 * StorageErrorEvent.PUT_ERROR, StorageEvent.PUT_COMPLETED, StorageEvent.EXTRACT_COMPLETED, 
		 * StorageEvent.PUT_STARTED, ProgressEvent.PROGRESS
		 * StorageErrorEvent.PROPERTY_LIST_ERROR 
		 */
		function startPutArchiveDialog(fileFilter:FileFilter=null):void;

		
		/**
		 * Cancels startPutDialog() actions 
		 */
		function cancelPut():void;
		

		/**
		 * Removes resource pointed by the 'path' property.  
		 * Following events should be dispatched while perfoming:
		 * StorageErrorEvent.REMOVE_ERROR,StorageEvent.REMOVE_COMPLETED
		 */
		function remove():void;
		
		
		/**
		 * List out all files from the resource 'path'.
		 * Following events should be dispatched while perfoming: 
		 * StorageListEvent.LIST_DIR_COMPLETED, StorageErrorEvent.LIST_DIR_ERROR  
		 */
		 
		function listDir():void;
		
		/**
		 * Saves file content at the selected 'path'
		 * @param content data to be saved   
		 * @param transactionId transaction id if opened (optional) 
		 * Following events should be dispatched while perfoming:
		 * StorageErrorEvent.SAVE_ERROR,StorageEvent.SAVE_COMPLETED   
		 */
		 
		function save(content:String, transactionId:String = null):void;
		
		
		/**
		 * Save binary file method. Target path is defined by 'path' property 
		 * @param content bytes to save   
		 * @param transactionId transaction id if opened (optional)
		 * Following methods should be dispatched resource:
		 * StorageErrorEvent.SAVE_ERROR,StorageEvent.SAVE_COMPLETED   
		 */
		function saveBytes(content:ByteArray, transactionId:String = null):void;
		
		
		/**
		 * Copies file from path specified in 'source' parameter. 
		 * Target path is defined by Resource 'path' property
		 * @param source "copy from" path 
		 * @param dataFormat - data format defined by the URLLoaderDataFormat class constans. ( TEXT by default )
		 */ 
		function copyFrom(source:String, dataFormat:String=null):void 
		
		/**
		 * Makes preview icon from given file in given path on server
		 * @param sourceFilePath path of source file
		 * @param iconDestPath path of destination icon - icon/fileName if no set
		 * @param type source file content type (image/movie). If no set server tries to recognize.
		 * @param iconWidth destination icon width, default is 200
		 * @param iconWidth destination icon height, default is 200
		 */  
		function makeIcon(iconDestPath:String = null, type:String=null, iconWidth:int=-1, iconHeight:int=-1):void
		
		/**
		 * Path to Resource. 
		 * @return path string containg path;
		 */ 
		 
		function get path():String;
		
		/**
		 * String representing resource type (folder or file)  
		 */
		function get type():String;   
		
		/**
		 * Starts save trancaction
		 */ 
		function setBegin():void 
		
		
		/**
		 * Ends save transaction
		 * @param id transaction identifier
		 */ 
		function setEnd(id:String):void
		
		/**
		 * Ping for locking material
		 */ 
		function ping():void
		 
		/**
		 * creates folder
		 */
		function createDir():void

		
	}
}